﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineCooperation.DB;
using OnlineCooperation.Entity;

namespace OnlineCooperation
{
    public partial class ResetUserInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Email.Value = Session["UserEmail"].ToString();
        }

        protected void ButtonResetPwdClick(object sender, EventArgs e)
        {
            UserDB ud = new UserDB();
            User u = ud.GetUserByEmail(Session["UserEmail"].ToString());

            string name = NewName.Value;
            if (name == "")
                name = u.Name;
            
            u = new User(u.ID, name, Session["UserEmail"].ToString(), u.Pwd, u.Icon);
            int code = ud.Update(u);

            switch (code)
            {
                case 0:
                    Response.Write("<script>alert('用户名已存在')</script>");
                    break;
                default:
                    Session["UserName"] = u.Name;
                    Response.Write("<script>alert('修改成功');window.location='HomePageJump.aspx';</script>");
                    break;
            }
             
        }
    }
}